<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/theme.css">
    <style>
        #footer {
            padding: 15px 0;
            background: #fff;
            border-top: 1px solid #ddd;
            text-align: center;
        }

        #topcontrol {
            color: #fff;
            z-index: 99;
            width: 30px;
            height: 30px;
            font-size: 20px;
            background: #222;
            position: relative;
            right: 14px !important;
            bottom: 11px !important;
            border-radius: 3px !important;
        }

        #topcontrol:after {
            /*top: -2px;*/
            left: 8.5px;
            content: "\f106";
            position: absolute;
            text-align: center;
            font-family: FontAwesome;
        }

        #topcontrol:hover {
            color: #fff;
            background: #18ba9b;
            -webkit-transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -o-transition: all 0.3s ease-in-out;
            transition: all 0.3s ease-in-out;
        }

        .label-type, .label-status, .label-order {
            background-color: #fff;
            color: #f60;
            padding: 5px;
            border: 1px #f60 solid;
        }

        #typeList :not(:first-child) {
            margin-top: 20px;
        }

        .label-text {
            margin: 0 10px;
        }

        .panel {
            border-radius: 0;
        }

        h3.break {
            font-size: 16px;
            display: block;
            white-space: nowrap;
            word-wrap: normal;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        h3.break > a {
            text-decoration: none;
        }
    </style>
</head>
<body>
<div class="navbar-wrapper">
    <div class="container">
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#" style="font-size:32px;">互联网众筹系统</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse" style="float:right;">
                    <ul class="nav navbar-nav">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i
                                    class="glyphicon glyphicon-user"></i><span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="member.html"><i class="glyphicon glyphicon-scale"></i> 会员中心</a></li>
                                <li><a href="#"><i class="glyphicon glyphicon-comment"></i> 消息</a></li>
                                <li class="divider"></li>
                                <li><a href="index.html"><i class="glyphicon glyphicon-off"></i> 退出系统</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
</div>

<div class="container theme-showcase" role="main">

    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <nav class="navbar navbar-default" role="navigation">
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li>
                                <a rel="nofollow" href="http://localhost/doIndexUI"><i
                                        class="glyphicon glyphicon-home"></i> 众筹首页</a>
                            </li>
                            <li class="active">
                                <a rel="nofollow" href="javascript:;"><i class="glyphicon glyphicon-th-large"></i> 项目总览</a>
                            </li>
                            <li>
                                <a rel="nofollow" href="http://localhost/doStart"><i
                                        class="glyphicon glyphicon-edit"></i> 发起众筹</a>
                            </li>
                            <li>
                                <a rel="nofollow" href="http://localhost/doMinecrowdfunding"><i
                                        class="glyphicon glyphicon-user"></i>
                                    我的众筹</a>
                            </li>
                        </ul>
                    </div>
                </nav>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <ul id="typeList" style="list-style: none;">
                            <li>
                                分类：<span class="label-type actvie">全部</span> <span class="label-text">科技</span> <span
                                    class="label-text">设计</span> <span class="label-text">公益</span> <span
                                    class="label-text">农业</span> <span class="label-text">文化</span>
                            </li>
                            <li>
                                状态：<span class="label-status actvie">全部</span> <span class="label-text">即将开始</span>
                                <span class="label-text">众筹中</span> <span class="label-text">众筹成功</span>
                            </li>
                            <li>
                                排序：<span class="label-order actvie">综合排序</span> <span class="label-text">最新上线</span>
                                <span class="label-text">金额最多</span> <span class="label-text">支持最多</span>
                            </li>
                        </ul>
                    </div>
                    <div class="panel-footer" style="height:50px;padding:0;">
                        <div style="float:left;padding:15px;" class="rowCount">
                            共(116)个众筹项目
                        </div>
                        <div style="float:right;">
                            <form class="navbar-form navbar-left" role="search">
                                <div class="form-group">
                                    <input type="text" id="searchNameId" class="form-control" placeholder="请输入搜索内容">
                                </div>
                                <button type="submit" class="btn btn-default" id="search"><i
                                        class="glyphicon glyphicon-search"></i>
                                    搜索
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="row" id="cols">
                    <div class="col-md-3">
                        <div class="thumbnail">
                            <img alt="300x200" src="img/product-1.jpg"/>
                            <div class="caption">
                                <h3 class="break">
                                    <a href="project.html">活性富氢净水直饮机</a>
                                </h3>
                                <p>
                                <div style="float:left;"><i class="glyphicon glyphicon-screenshot" title="目标金额"></i>
                                    $20,000
                                </div>
                                <div style="float:right;"><i title="截至日期" class="glyphicon glyphicon-calendar"></i>
                                    2017-20-20
                                </div>
                                </p>
                                <br>
                                <div class="progress" style="margin-bottom: 4px;">
                                    <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40"
                                         aria-valuemin="0" aria-valuemax="100" style="width: 40%">
                                        <span>40% </span>
                                    </div>
                                </div>
                                <div><span style="float:right;"><i class="glyphicon glyphicon-star-empty"></i></span>
                                    <span><i class="glyphicon glyphicon-user" title="支持人数"></i> 12345</span></div>
                            </div>
                        </div>
                    </div>
                    <div>数据加载中...</div>
                </div>

            </div>
        </div>
    </div>

    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column" style="text-align:center">
                <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                <div id="Searchresult"></div>
                <div id="hiddenresult" style="display:none;" class="pagination">
                    <div class="result">第1项内容</div>
                    <div class="result">第2项内容</div>
                    <div class="result">第3项内容</div>
                    <div class="result">第4项内容</div>
                    <div class="result">第5项内容</div>
                    <div class="result">第6项内容</div>
                    <div class="result">第7项内容</div>
                    <div class="result">第8项内容</div>
                </div>
            </div>
        </div>
    </div>

    <div class="container" style="margin-top:20px;">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div id="footer">
                    <div class="footerNav">
                        <a rel="nofollow" href="http://www.atguigu.com">关于我们</a> | <a rel="nofollow"
                                                                                      href="http://www.atguigu.com">服务条款</a>
                        | <a rel="nofollow" href="http://www.atguigu.com">免责声明</a> | <a rel="nofollow"
                                                                                        href="http://www.atguigu.com">网站地图</a>
                        | <a rel="nofollow" href="http://www.atguigu.com">联系我们</a>
                    </div>
                    <div class="copyRight">
                        Copyright ?2010-2014atguigu.com 版权所有
                    </div>
                </div>

            </div>
        </div>
    </div>

</div> <!-- /container -->

<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<!-- pagination分页插件的引入,在jquery之后引入; -->
<link rel="stylesheet" src="css/pagination.css">
<script type="text/javascript" src="jquery/jquery.pagination.js"></script>

<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script/docs.min.js"></script>
<!-- bootstrap datepicker -->
<script type="text/javascript" src="script/back-to-top.js"></script>
<script type="text/javascript">
    //  JS 问题如何解决? console.log(),debugger,排除法

    /* 页面加载完后.立马执行的函数; */
    $(function () {
        doGetProjectsObjects();
        //注册查询点击事件;
        $(".navbar-left").on("click", "#search", doQueryObjects);

    });

    /* 1-- 通过异步加载项目展示页面; */
    function doGetProjectsObjects() {
        //1.定义请求url
        const url = "portalproject/doGetPortalProjectPageObjects";

        //2.定义请求参数
        var pageCurrent = $("#pageId").data("pageCurrent1");
        if (!pageCurrent) pageCurrent = 1;
        let params = "pageCurrent=" + pageCurrent;
        //2.1.判断文本框中的projectName;
        var projectName = $("#searchNameId").val();   //复选框的id值;
        if (projectName) {
            params = params + "&projectName=" + projectName;
        }

        //3.发送异步请求并处理响应结果
        // $.getJSON(url,params,function(result){//JsonResult
        //	 doHandleQueryResult(result);
        //});
        //也可以按照如下结构进行异步请求
        $.getJSON(url, params, doHandleProjectsResult);
    }

    /* 2-- 程序信息的方法 */
    function doHandleProjectsResult(result) {//JsonResult
        //debugger
        //console.log("result", result);
        if (result.state == 1) {//正常数据
            doSetTableBodyCols(result.data.records);

            //第二步:将分页信息更新到页面上
            //console.log(result.data.pageCurrent);
            doSetPagination(result.data);

        } else {
            alert(result.message);
        }
    }

    /* 3-- 把数据插入到tbody内部的方法  */
    function doSetTableBodyCols(records) {      //records是个数组;
        //1.获得tbody并清空;
        var div = $("#cols");
        div.empty();

        //2.插入tbody内部的行;遍历
        //上下方法都是遍历;
        for (let i = 0; i < records.length; i++) {
            //console.log(records[i]);
            div.append(doCreateCol(records[i]));

        }
    }

    /* 4-- 创建行的方法 */
    function doCreateCol(records) {     //records是一个数;
        return `<div class="col-md-3">
                        <div class="thumbnail">
                            <img alt="300x200" src="${records.headerPicturePath}"/>
                            <div class="caption">
                                <h3 class="break">
                                    <a href="http://localhost/doProject">${records.projectName}</a>
                                </h3>
                                <p>
                                <div style="float:left;"><i class="glyphicon glyphicon-screenshot" title="目标金额"></i>
                                    $<span>${records.money}</span>
                                </div>
                                <div style="float:right;"><i title="发起日期" class="glyphicon glyphicon-calendar"></i>
                                    ${records.deployDate}
                                </div>
                                </p>
                                <br>
                                <div class="progress" style="margin-bottom: 4px;">
                                    <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40"
                                         aria-valuemin="0" aria-valuemax="100" style="width: ${records.percentage}%">
                                        <span>${records.percentage}% </span>
                                    </div>
                                </div>
                                <div><span style="float:right;"><i class="glyphicon glyphicon-star-empty"></i></span>
                                    <span><i class="glyphicon glyphicon-user" title="支持人数"></i>${records.supporter}</span></div>
                            </div>
                        </div>
                    </div>`
    }

    /* 5-- 根据用户名查询事件 */
    function doQueryObjects() {
        //初始化当前页码值
        //$("#pageId").data("pageCurrent",1);
        //利用结果异步查询信息;
        doGetProjectsObjects();
    }

    /* 6-- 对页码和导航条进行初始化的方法; */
    function doSetPagination(pageObject) {
        //1.获取总记录数;
        var rowCount = pageObject.rowCount;
        //2.每页显示多少条;
        var pageSize = pageObject.pageSize;
        //3.当前页页码值;
        var pageCurrent = pageObject.pageCurrent;

        //4.声明一个JSON对象存储Pagination要设置的属性
        var properties = {
            num_edge_entries: 1, //边缘页数;
            num_display_entries: 3, //主体页数;
            callback: pageSelectCallback,   //点击翻页按钮式跳转页面,回调函数;
            items_per_page: pageSize, //每页显示1项;
            current_page: pageCurrent - 1, //// Pagination内部使用pageIndex来管理页码, pageIndex从0;
            prev_text: "上一页",
            next_text: "下一页"
        };

        //5.生成页码导航条;
        $("#Pagination").pagination(rowCount, properties);
    }

    //回调函数是声明出来以后给别人调用的;
    //pageIndex是Pagination穿过来的,页码从0开始,所以使用时要加1;
    /* 7-- 用户点击1,2,3这样的页码时,调用这个函数,实现页面的跳转; */
    function pageSelectCallback(pageIndex, jQuery) {
        //1.根据pageIndex计算得到pageCurrent;
        var pageCurrent = pageIndex + 1;
        // //2.跳转页面;
        //window.location.href ="doProjects?pageCurrent="+pageCurrent;
        doGetProjectsObjects2(pageCurrent);
        return false;

    }

    /* 8-- 通过异步加载项目展示页面; */
    function doGetProjectsObjects2(pageCurrent) {
        //1.定义请求url
        const url = "portalproject/doGetPortalProjectPageObjects";

        //2.定义请求参数
        if (!pageCurrent) pageCurrent = 1;
        let params = "pageCurrent=" + pageCurrent;
        //2.1.判断文本框中的projectName;
        var projectName = $("#searchNameId").val();   //复选框的id值;
        if (projectName) {
            params = params + "&projectName=" + projectName;
        }

        //3.发送异步请求并处理响应结果
        // $.getJSON(url,params,function(result){//JsonResult
        //	 doHandleQueryResult(result);
        //});
        //也可以按照如下结构进行异步请求
        $.post(url, params, doHandleProjectsResult2);
    }

    /* 9-- 程序信息的方法 */
    function doHandleProjectsResult2(result) {//JsonResult
        //debugger
        //console.log("result", result);
        if (result.state == 1) {//正常数据
            doSetTableBodyCols(result.data.records);

        } else {
            alert(result.message);
        }
    }


</script>
</body>
</html>